package com.yanqu.road.dao.impl.config;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.config.player.DecorationInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class DecorationDaoImpl extends TempDao {

    public void getDecorationInfoMap(Map<Integer, Map<Integer, DecorationInfo>> decorationInfoTypeMap, Map<Integer, DecorationInfo> decorationInfoMap) {
        ResultSet rs = null;
        CallableStatement call = null;
        String sql = "select * from t_p_decoration";
        try {
            getDb().setConnName(DbNameStrategy.getConfigDb());
            call = getDb().getConnection().prepareCall(sql);
            rs = call.executeQuery();
            while (rs.next()) {
                DecorationInfo data = new DecorationInfo();
                data.setId(rs.getInt("id"));
                data.setSex(rs.getShort("sex"));
                data.setType(rs.getInt("type"));
                data.setFree(rs.getBoolean("isFree"));
                if(!decorationInfoTypeMap.containsKey(data.getType())){
                    decorationInfoTypeMap.put(data.getType(), new ConcurrentHashMap<>());
                }
                decorationInfoTypeMap.get(data.getType()).put(data.getId(), data);
                decorationInfoMap.put(data.getId(), data);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        } finally {
            getDb().closeConnection(call, rs);
        }
    }
}
